<?php
function plugin_render() {
    $result = '';
    if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['a'], $_POST['b'], $_POST['op'])) {
        $a = floatval($_POST['a']);
        $b = floatval($_POST['b']);
        $op = $_POST['op'];
        switch ($op) {
            case '+': $result = $a + $b; break;
            case '-': $result = $a - $b; break;
            case '*': $result = $a * $b; break;
            case '/': $result = ($b != 0) ? $a / $b : '除数不能为0'; break;
            default: $result = '未知操作'; break;
        }
    }
    ?>
    <form method="post" class="space-y-4">
      <div class="flex space-x-2">
        <input type="number" step="any" name="a" class="border rounded px-2 py-1 w-24" required placeholder="数字A">
        <select name="op" class="border rounded px-2 py-1">
          <option value="+">+</option>
          <option value="-">-</option>
          <option value="*">×</option>
          <option value="/">÷</option>
        </select>
        <input type="number" step="any" name="b" class="border rounded px-2 py-1 w-24" required placeholder="数字B">
        <button type="submit" class="bg-blue-500 text-white px-4 py-1 rounded">计算</button>
      </div>
      <?php if ($result !== ''): ?>
        <div class="text-green-600 font-bold">结果：<?php echo htmlspecialchars($result); ?></div>
      <?php endif; ?>
    </form>
    <?php
} 